<?php
/**
 * Created by PhpStorm.
 * User: Dave
 * Date: 2018/8/14
 * Time: 17:18
 */

namespace Biz\module\Behaviors\Stock;

use Biz\model\activity\AllActivitySku as mAllActivitySku;
use Biz\cache\AllActivityStock as cAllActivityStock;
use Biz\model\GoodsStockLog;
use Biz\pockets\constInterface\ActivityInfo as sActivityInfo;

class AllActivityStock  extends StockBehaviorsAbstruct
{
    const TYPE_LOG = GoodsStockLog::TYPE_LIMIT_TIME_ROBBING;

    public static function setStocksCache($goods_ids)
    {
        return true;
    }


    public static function updateDbStock($stockInfo)
    {
        mAllActivitySku::updateActualStock($stockInfo);
        foreach ($stockInfo as $item) {
            if ($item['promo_type'] == sActivityInfo::ACTIVITY_TYPE_PINTUAN) {
                PintuanStock::updateDbStock([$item['sku_id'] => $item['stock']]);
            } else if ($item['promo_type'] == sActivityInfo::ACTIVITY_TYPE_LIMIT_TIME_ROB) {
                LimitTimeStock::updateDbStock([$item['sku_id'] => $item['stock']]);
            } else if ($item['promo_type'] == sActivityInfo::ACTIVITY_TYPE_ZHUYOUJINTIE) {
                LimitTimeStock::updateDbStock([$item['sku_id'] => $item['stock']]);
            }
        }
    }

    public static function IncrStocksCounter($stockInfo)
    {
        foreach ($stockInfo as $info)
        {
            $result[] = cAllActivityStock::incrActivityStock($info['promo_id'], $info['promo_type'], $info['goods_id'], ['sku_id'=>$info['sku_id'], 'buy_num' => $info['buy_num']]);
        }

        return array_combine(array_column($stockInfo, "sku_id"), $result);
    }

    public static function DecrStocksCounter($stockInfo)
    {
        foreach ($stockInfo as $info)
        {
            $result[] = cAllActivityStock::decrActivityStock($info['promo_id'], $info['promo_type'], $info['goods_id'], ['sku_id'=>$info['sku_id'], 'buy_num' => $info['buy_num']]);
        }

        return array_combine(array_column($stockInfo, "sku_id"), $result);
    }
}